package com.jemframework.domain;

import javax.persistence.EntityManager;

import com.jemframework.Context;
import com.jemframework.domain.identifier.Identifier;

public class EntityFinder {

  private static final EntityFinder INSTANCE = new EntityFinder();

  public static EntityFinder getInstance() {
    return INSTANCE;
  }

  private EntityFinder() {
    super();
  }

  @SuppressWarnings("unchecked")
  public <E extends Entity> E findEntity(EntityManager em, Identifier anIdentifier) {
    EntityHome theEntityHome = Context.getInstance().getEntityHomeFactory().getEntityHome(anIdentifier.getEntityType());
    E theEntity = (E) theEntityHome.findEntity(em, anIdentifier);
    return theEntity;
  }
}
